package cn.com.hbhgkj.dao.hibernate;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import cn.com.hbhgkj.common.DaoException;
import cn.com.hbhgkj.common.Pagination;
import cn.com.hbhgkj.dao.CopyrightRegisterationDao;
import cn.com.hbhgkj.pojo.CopyrightRegisteration;

public class CopyrightRegisterationDaoImpl extends
		GenericDaoImpl<CopyrightRegisteration, Long> implements
		CopyrightRegisterationDao {

	public List<CopyrightRegisteration> findLikeCopyrighter(String copyrighter,
			Pagination pagination) throws DaoException {
		try {
			DetachedCriteria criteria = this.createCriteria();
			criteria.add(Restrictions.like("copyrighter", copyrighter,
					MatchMode.ANYWHERE));
			criteria.addOrder(Order.desc("registDate"));
			pagination.setTotalCount(this.getTotalCount(criteria));
			return this.getHibernateTemplate().findByCriteria(criteria,
					pagination.getStart(), pagination.getPageSize());
		} catch (Exception e) {
			throw new DaoException(e);
		}
	}

	public List<CopyrightRegisteration> findBySeriaNum(String seriaNum)
			throws DaoException {
		try {
			DetachedCriteria criteria = this.createCriteria();
			criteria.add(Restrictions.eq("serialNum", seriaNum));
			return this.getHibernateTemplate().findByCriteria(criteria);
		} catch (Exception e) {
			throw new DaoException(e);
		}
	}

}
